package com.stsolutions.budgetcontroller;

import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import com.stsolutions.budgetcontroller.db.DaoObject;
import com.stsolutions.budgetcontroller.db.DataBaseActions;
import com.stsolutions.budgetcontroller.db.DatabaseHelper;
import com.stsolutions.budgetcontroller.model.data.CostBucket;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ShowCostsActivity extends OrmLiteBaseActivity<DatabaseHelper>
		implements OnClickListener {
	private Button goBackBtn;
	private Button newCostBtn;
	private TextView showCostsTextView;
	protected final String LOG_TAG = getClass().getSimpleName();

	private CostBucket bucket;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.showcosts);

		newCostBtn = (Button) findViewById(R.id.newCostBtn);
		newCostBtn.setOnClickListener(this);

		// getting right bucket:
		Bundle extras = getIntent().getExtras();
		int bucketId = extras.getInt("costBucketSelected");
		Log.i(ShowCostsActivity.class.getName(), "Cost bucket index = "
				+ bucketId);
		bucket = (CostBucket) getHelper().doDataBaseAction(
				DataBaseActions.ACTION_GET_ITEM_BY_ID, bucketId, null,
				DaoObject.COST_BUCKET);

		showCostsTextView = (TextView) findViewById(R.id.resultText);
		if (bucket != null) {
			showCostsTextView.setText(bucket.printCosts());
		}
		goBackBtn = (Button) findViewById(R.id.goBackBtn);
		goBackBtn.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.goBackBtn:
			Intent mainWindow = new Intent(this, BudgetControllerActivity.class);
			startActivity(mainWindow);
			break;
		case R.id.newCostBtn:
			Intent newCostWindow = new Intent(this, NewCostActivity.class);
			newCostWindow.putExtra("costBucketSelected",
					bucket.getCostBucketId());
			startActivity(newCostWindow);
		default:
			break;
		}
	}
}
